package de.homelabs.persistence.h2;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="testitems")
public class TestItem implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	
	@ManyToOne
	@JoinColumn(name="parent_id")
	private TestItem parent;
	
	@OneToMany(mappedBy="parent", cascade=CascadeType.ALL)
	private Set<TestItem> children = new HashSet<TestItem>();

	
	/*******************
	 * getter / setter *
	 *******************/
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public TestItem getParent() {
		return parent;
	}

	public void setParent(TestItem parent) {
		this.parent = parent;
	}

	public Set<TestItem> getChildren() {
		return children;
	}

	public void setChildren(Set<TestItem> children) {
		this.children = children;
	}
}
